#ifndef ESP32_MANAGER_H
#define ESP32_MANAGER_H

#include <stdint.h>

class ESP32Manager 
{
    typedef void(*CallbackFunction_t)(void);
    typedef void(*EventFunction_t)(int, int);

    typedef struct {
        CallbackFunction_t SetupCallback;
        CallbackFunction_t LoopCallback;
        CallbackFunction_t ExitCallback;
        EventFunction_t EventCallback;
    } PageList_T;

public:
    void init(uint8_t pageMax, uint8_t pageStackSize);
    void dnit();

    uint8_t NowPage, LastPage, NextPage;
    uint8_t NewPage, OldPage;

    bool PageRegister(
        uint8_t pageID,
        CallbackFunction_t setupCallback,
        CallbackFunction_t loopCallback,
        CallbackFunction_t exitCallback,
        EventFunction_t eventCallback
    );

    int8_t PagePop();
    int8_t PagePush(uint8_t pageID);
    bool PageClear(uint8_t pageID);
    void PageChangeTo(uint8_t pageID);
    void PageEventTransmit(int key, int event);
    void PageStackClear();
    void Running();

private:
    PageList_T* PageList;
    uint8_t *PageStack;
    uint8_t PageStackSize;
    uint8_t PageStackTop;
    uint8_t MaxPage;
    bool IsPageBusy;
};

#endif